<template>
  <div>
    <el-dialog :title="title" :visible.sync="detailvisible" width="90%" append-to-body class="my-dialog homedialog" @close="cancel">
      <pointDetail :pointId="pointId" type="homeindex"></pointDetail>
    </el-dialog>
  </div>
</template>

<script>
import {listStagnationPoint} from "@/api/system/stagnation_point";
import pointDetail from "@/views/system/stagnation_point/detail"

export default {
  name: "index",
  props: ['visible', 'pointId'], // param 执勤点信息
  dicts: ['sys_stagnation_type'],
  components:{pointDetail},
  data() {
    return {
      teamlist: [],
      detailvisible: false,
      title: '执勤点信息',
      // 遮罩层
      loading: true,
      // 选中数组
      layout: 'total, sizes, prev, pager, next',
      // 总条数
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: ''
      },
      zhudianVisible: false,
      teamVisible: false,
      paramId: 0,
      paramPoint: null
    }
  },
  watch: {
    visible() {
      this.detailvisible = this.visible
      if (this.visible) {
        this.getList()
      } else {
      }
    }
  },
  created() {
  },
  methods: {
    /** 查询定位器列表 */
    getList() {
      this.loading = true;
      listStagnationPoint(this.queryParams).then(response => {
        this.teamlist = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    submitForm() {
      if (!this.dealerItem) {
        this.$message.error(this.title)
        return
      }
      let that = this
      console.log('dealerItem:', this.dealerItem, that.queryData)
      // type batchBindingUser 批量绑定设备； bindingUser 单独绑定设备
      if (this.type == 'bindingUser') {
        this.$modal
          .confirm(`确定将该设备绑定至【${this.dealerItem.realName}】,是否继续？`)
          .then(function () {
            return DevideBindingUser({
              deviceIds: [that.queryData.deviceId],
              dealerId: that.dealerItem.adminId
            });
          })
          .then(() => {
            this.$modal.msgSuccess("绑定成功");
            this.$emit('getList')
            this.cancel()
          })
          .catch(() => {
          });
        return
      }
      if (this.type == 'batchBindingUser') {
        this.$modal
          .confirm(`确定为经销商【${this.dealerItem.realName}】批量绑定【${this.queryData.length}】台设备,是否继续？`)
          .then(function () {
            return DevideBindingUser({
              deviceIds: that.queryData,
              dealerId: that.dealerItem.adminId
            });
          })
          .then(res => {
            // this.$modal.msgSuccess("绑定成功");
            // this.messegeFn(res.msg)
            this.$emit('getList')
            this.cancel()
          })
          .catch(() => {
          });
        return
      }
      this.$emit('dealerGet', this.dealerItem)
      this.cancel()
    },
    cancel() {
      this.$emit('update:visible', false)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.dealerId = ''
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dealerId = ''
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleViewTeam(row) {
      this.paramPoint = JSON.parse(JSON.stringify(row))
      this.teamVisible = true
    },
    handleUpdate(row) {
      this.paramId = row.id
      this.zhudianVisible= true
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.name + '"执勤点吗？').then(function () {
        return updateStagnationPoint({id: row.id, status: row.status});
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function () {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
  }
}
</script>

<style scoped>
.el-dialog__body{
  padding: 0;
}
</style>
